﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

public class BuffData
{
    public float duing;
}

// buff
public abstract class BuffBase
{
    public int ID { get; protected set; }
    public float During { get; protected set; }

    private Action<int> _endCallback;

    protected TimerMgr.Timer _timer;

    protected HumanCtrl _owner;
    public virtual void Init(int id, HumanCtrl owner, Action<int> endCallback)
    {
        ID = id;
        _owner = owner;
        _endCallback = endCallback;
    }

    public void Start()
    {
        reset();
        onStart();
    }

    protected virtual void onStart()
    {
        _timer = TimerMgr.Instance.CreateTimer(During, 1, onFinish);
        _timer.Start();
    }

    protected virtual void onFinish()
    {
        reset();

        if (_endCallback != null) { _endCallback(ID); }
    }

    private void reset()
    {
        if (_timer != null)
        {
            _timer.Stop();
        }
        _timer = null;

    }

    // 添加一个特效
    protected GameObject addEffect(string path)
    {
        var e = ResMgr.Instance.GetGameObject(path);
        e.transform.SetParent(_owner.EffectRoot, false);

        return e;
    }

    // 碰到阻挡物。true:技能发挥作用
    public virtual bool OnBlockEnter(Transform other)
    {
        return false;
    }
    // 碰到怪物。true:技能发挥作用
    public virtual bool OnEnemyEnter(Enemy other)
    {
        return false;
    }

    public void AddDuring(float addDuring)
    {
        // 重新计时效果(增加的时间，减去剩余的时间)
        During += addDuring - _timer.LeftTimeInCurCycle;
        if (_timer != null)
        {
            _timer.DuringTime = During;
        }
    }
}

